var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("GameEm"),
    s = t("CallRoad"),
    c = t("GetCoinNode"),
    p = t("TableFoodView"),
    l = cc._decorator,
    d = l.ccclass,
    u =
        (l.property,
        l.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.road = [];
                e.foodObjData = {};
                e.curViewIndexDataList = {};
                e.foodTipList = {};
                e.curViewIndexPosList = {};
                e.tabIsWanMei = {};
                e.updateViewIndexView = {};
                e.updateViewIndexViewKind = {};
                e.parentNode = null;
                e.parentSort = null;
                e.freeCostNode = {};
                return e;
            }
            e.prototype.checkSort = function () {
                var t = this;
                EVUIEffView.emit(EVUIEffView.callSort, function (e) {
                    t.parentSort = e;
                });
            };
            e.prototype.onLoad = function () {
                EvCat.on(EvCat.updateFoodView, this.buildFoodView.bind(this), this);
                EvCat.on(EvCat.addFoodCoin, this.addFooIndex.bind(this), this);
            };
            e.prototype.addFooIndex = function (t, e, o, a) {
                this.checkSort();
                var i = this.getFoodParent();
                if (e && i) {
                    var n = ParseTool.parseAbc(o),
                        r = PlayEffectDo.playPsCom(
                            this.getFoodParent(),
                            i.convertToWorldSpaceAR(e),
                            QLooperNode.tag_addCoin
                        );
                    ParseTool.setSortIndex(r, 2e3);
                    var s = PlayEffectDo.playCoinNum(
                        this.getFoodParent(),
                        i.convertToWorldSpaceAR(e),
                        QLooperNode.tag_addCoinItem,
                        n
                    );
                    ParseTool.setSortIndex(s, 2e3);
                    a >= 0 && this.checkAddCoin(e, o, a);
                } else console.log("BuildFood ----------------- 重大bug ", i, e);
            };
            e.prototype.checkAddCoin = function (t, e, o) {
                var a = CacheDataManager.getLvUpgradeValueData(r.UpgradeData.xiaofei);
                if (!(Math.random() > a)) {
                    var i = CacheDataManager.getLvUpgradeValueData(r.UpgradeData.perfectRateAdd),
                        n = 1 + CacheDataManager.getAddAllAddtion(r.AddtionData.xfzj);
                    n *= i;
                    e = CacheDataManager.mulDot(e, n);
                    if (this.freeCostNode[o]) (p = this.freeCostNode[o]).addCost(e);
                    else {
                        var s = QLooperNode.getNode(QLooperNode.tag_getCoinNode);
                        if (s) {
                            s.parent = this.getFoodParent();
                            s.setPosition(t);
                            ParseTool.setSortIndex(s, 300);
                            var p;
                            if ((p = s.getComponent(c.default))) {
                                p.setBuildFood(o, e, this.removeCoin.bind(this));
                                this.freeCostNode[o] = p;
                            }
                        }
                    }
                }
            };
            e.prototype.removeCoin = function (t) {
                this.freeCostNode[t] = null;
            };
            e.prototype.buildFoodView = function (t, e, o, a, i, n, s) {
                var c = this;
                EVUIEffView.emit(EVUIEffView.callRoad, r.CookingCallKey.catTable, 0, function (t) {
                    c.parentNode = t;
                });
                if (i) this.foodObjData[a] = this.getFoodId(a) + 1;
                else {
                    this.foodObjData[a] = this.getFoodId(a) - 1;
                    CacheDataManager.setFoodTabCount(e, -1);
                }
                this.checkCurFood(e, o, a, i, n, s);
                this.updateView();
            };
            e.prototype.checkCurFood = function (t, e, o, a, i, n) {
                if (!this.curViewIndexDataList[t]) {
                    this.curViewIndexDataList[t] = [];
                    this.foodTipList[t] = [];
                }
                this.tabIsWanMei[t] || (this.tabIsWanMei[t] = []);
                if (a) {
                    this.tabIsWanMei[t].push(i);
                    this.curViewIndexDataList[t].push(o);
                    this.foodTipList[t].push(n);
                    this.curViewIndexPosList[t] = e;
                } else if (this.curViewIndexDataList[t].length > 0)
                    for (var r = 0; r < this.curViewIndexDataList[t].length; r++)
                        if (this.curViewIndexDataList[t][r] == o) {
                            this.foodTipList[t].splice(r, 1);
                            this.curViewIndexDataList[t].splice(r, 1);
                            this.tabIsWanMei[t].splice(r, 1);
                            break;
                        }
            };
            e.prototype.getFoodParent = function () {
                return this.parentSort;
            };
            e.prototype.updateView = function () {
                var t = this;
                this.checkSort();
                if (this.parentSort) {
                    for (var e in this.curViewIndexDataList)
                        if (this.curViewIndexDataList[e].length > 0) {
                            var o = this.curViewIndexDataList[e][this.curViewIndexDataList[e].length - 1],
                                a = this.foodTipList[e][this.foodTipList[e].length - 1],
                                i = !!this.tabIsWanMei[e][this.tabIsWanMei[e].length - 1];
                            if (this.updateViewIndexViewKind[e] != o) {
                                this.updateViewIndexViewKind[e] = o;
                                if (!this.updateViewIndexView[e]) {
                                    this.updateViewIndexView[e] = QLooperNode.getNode(QLooperNode.tag_tableFoodView);
                                    this.updateViewIndexView[e].parent = this.getFoodParent();
                                    this.updateViewIndexView[e].setPosition(this.curViewIndexPosList[e]);
                                }
                                if (this.updateViewIndexView[e]) {
                                    var n = (r = this.updateViewIndexView[e]).getComponent(p.default);
                                    if (n) {
                                        n.isPrefab.active = i;
                                        n.setFoodView(o, a);
                                    }
                                }
                            }
                        } else {
                            var r = this.updateViewIndexView[e];
                            this.updateViewIndexView[e] = null;
                            this.updateViewIndexViewKind[e] = null;
                            r && QLooperNode.putNode(r);
                        }
                } else
                    this.scheduleOnce(function () {
                        t.updateView();
                    }, 0.1);
            };
            e.prototype.getFoodId = function (t) {
                return this.foodObjData[t] || 0;
            };
            e.prototype.onDestroy = function () {
                EvCat.offTarget(this);
            };
            e.prototype.init = function () {
                var t = this;
                EVUIEffView.emit(EVUIEffView.callRoad, r.CookingCallKey.catTable, 0, function (e) {
                    for (var o = e.getComponent(s.default), a = 0; a < o.callRoadList.length; a++)
                        t.road.push(o.callRoadList[a]);
                });
            };
            return n([d], e);
        })(cc.Component));
o.default = u;
